// 区分开发环境和生产环境  接口地址


export const baseUrl = 'https://ht.rhzsz.com/api'; //正式地址
// export const baseUrl = 'https://www.djkip.online/api'; //测试地址
// export const baseUrl = 'http://192.168.31.53:9505'; //本地服务器
import store from '@/store/index.js'; //需要引入store
export function https(config) {
	//设置请求头
	config.header = {
		'content-type': 'application/json;charset=utf-8',
		'X-Access-Token': uni.getStorageSync('Token') || '',
	};
	config.url = baseUrl + config.url; // 请求地址
	let promise = new Promise(function(resolve, reject) {
		uni.request(config).then(res => {
			if(res.data.code == 401){
				uni.setStorageSync('Token',null)
				uni.navigateTo({
					url:'/pages/index/login/login'
				})
			}
			resolve(res);
		}).catch(error => {
			console.log(error)
			reject(error);
		})
	})
	return promise
}
export const uploadFilePromise = function(url) {
	return new Promise((resolve, reject) => {
		let a = uni.uploadFile({
			url: baseUrl + '/gzsd/api/file/upload', // 仅为示例，非真实的接口地址
			filePath: url,
			name: 'file',
			header: {
				// "content-type":"multipart/form-data",
				'X-Access-Token': uni.getStorageSync('Token'),
			},
			success: (res) => {
				resolve(JSON.parse(res.data))
			},
			fail(err) {
				console.log("请求失败的结果", err);
				reject(err);
			}
		});
	})
}